package com.mob.tools.gui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class PullToRequestView extends RelativeLayout
{
  private static final long MIN_REF_TIME = 1000L;
  private PullToRequestAdatper adapter;
  private View bodyView;
  private float downY;
  private int footerHeight;
  private View footerView;
  private int headerHeight;
  private View headerView;
  private long pullTime;
  private boolean pullingDownLock;
  private boolean pullingUpLock;
  private int state;
  private Runnable stopAct;
  private int top;

  public PullToRequestView(Context paramContext)
  {
    super(paramContext);
    init();
  }

  public PullToRequestView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init();
  }

  public PullToRequestView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    init();
  }

  private boolean canPullDown()
  {
    return (!this.pullingDownLock) && (this.adapter.isPullDownReady()) && (this.state == 0);
  }

  private boolean canPullUp()
  {
    return (!this.pullingUpLock) && (this.adapter.isPullUpReady()) && (this.state == 0);
  }

  private MotionEvent getCancelEvent(MotionEvent paramMotionEvent)
  {
    return MotionEvent.obtain(paramMotionEvent.getDownTime(), paramMotionEvent.getEventTime(), 3, paramMotionEvent.getX(), paramMotionEvent.getY(), paramMotionEvent.getMetaState());
  }

  private void init()
  {
    this.stopAct = new Runnable()
    {
      public void run()
      {
        PullToRequestView.this.reversePulling();
      }
    };
  }

  private void performFresh()
  {
    this.pullTime = System.currentTimeMillis();
    this.state = 1;
    if (this.adapter != null)
      this.adapter.onRefresh();
  }

  private void performRequestNext()
  {
    this.pullTime = System.currentTimeMillis();
    this.state = -1;
    if (this.adapter != null)
      this.adapter.onRequestNext();
  }

  private void reversePulling()
  {
    this.top = 0;
    scrollTo(0, 0);
    this.state = 0;
    if (this.adapter != null)
      this.adapter.onReversed();
  }

  public boolean dispatchTouchEvent(MotionEvent paramMotionEvent)
  {
    switch (paramMotionEvent.getAction())
    {
    default:
    case 0:
    case 2:
    case 1:
    case 3:
    }
    while (true)
    {
      return super.dispatchTouchEvent(paramMotionEvent);
      this.downY = paramMotionEvent.getY();
      continue;
      float f = paramMotionEvent.getY();
      switch (this.state)
      {
      case 0:
      default:
        if (this.top > 0)
        {
          this.top = ((int)(this.top + (f - this.downY) / 2.0F));
          if (this.top < 0)
            this.top = 0;
          scrollTo(0, -this.top);
          if (this.adapter != null)
            this.adapter.onPullDown(100 * this.top / this.headerHeight);
          paramMotionEvent = getCancelEvent(paramMotionEvent);
        }
        break;
      case 1:
      case -1:
      }
      while (true)
      {
        this.downY = f;
        break;
        this.top = ((int)(this.top + (f - this.downY) / 2.0F));
        if (this.top < 0)
          this.top = 0;
        scrollTo(0, -this.top);
        paramMotionEvent = getCancelEvent(paramMotionEvent);
        continue;
        this.top = ((int)(this.top + (f - this.downY) / 2.0F));
        if (this.top > 0)
          this.top = 0;
        scrollTo(0, -this.top);
        paramMotionEvent = getCancelEvent(paramMotionEvent);
        continue;
        if (this.top < 0)
        {
          this.top = ((int)(this.top + (f - this.downY) / 2.0F));
          if (this.top > 0)
            this.top = 0;
          scrollTo(0, -this.top);
          if (this.adapter != null)
            this.adapter.onPullUp(100 * -this.top / this.footerHeight);
          paramMotionEvent = getCancelEvent(paramMotionEvent);
        }
        else if (f > this.downY)
        {
          if (canPullDown())
          {
            this.top = ((int)(this.top + (f - this.downY) / 2.0F));
            scrollTo(0, -this.top);
            if (this.adapter != null)
              this.adapter.onPullUp(100 * -this.top / this.footerHeight);
            paramMotionEvent = getCancelEvent(paramMotionEvent);
          }
        }
        else if ((f < this.downY) && (canPullUp()))
        {
          this.top = ((int)(this.top + (f - this.downY) / 2.0F));
          scrollTo(0, -this.top);
          if (this.adapter != null)
            this.adapter.onPullUp(100 * -this.top / this.footerHeight);
          paramMotionEvent = getCancelEvent(paramMotionEvent);
        }
      }
      switch (this.state)
      {
      default:
        break;
      case -1:
        this.top = (-this.footerHeight);
        scrollTo(0, -this.top);
        break;
      case 0:
        if (this.top > this.headerHeight)
        {
          this.top = this.headerHeight;
          scrollTo(0, -this.top);
          if (this.adapter != null)
            this.adapter.onPullDown(100);
          performFresh();
          paramMotionEvent = getCancelEvent(paramMotionEvent);
        }
        else if (this.top < -this.footerHeight)
        {
          this.top = (-this.footerHeight);
          scrollTo(0, -this.top);
          if (this.adapter != null)
            this.adapter.onPullUp(100);
          performRequestNext();
          paramMotionEvent = getCancelEvent(paramMotionEvent);
        }
        else if (this.top != 0)
        {
          scrollTo(0, 0);
          if (this.adapter != null)
          {
            if (this.top <= 0)
              break label738;
            this.adapter.onPullDown(0);
          }
          while (true)
          {
            this.top = 0;
            break;
            this.adapter.onPullUp(0);
          }
        }
        break;
      case 1:
        label738: this.top = this.headerHeight;
        scrollTo(0, -this.top);
      }
    }
  }

  public void lockPullingDown()
  {
    this.pullingDownLock = true;
  }

  public void lockPullingUp()
  {
    this.pullingUpLock = true;
  }

  public void performPullingDown(boolean paramBoolean)
  {
    this.top = this.headerHeight;
    scrollTo(0, -this.top);
    if (paramBoolean)
      performFresh();
  }

  public void performPullingUp(boolean paramBoolean)
  {
    this.top = (-this.footerHeight);
    scrollTo(0, -this.top);
    if (paramBoolean)
      performRequestNext();
  }

  public void releasePullingDownLock()
  {
    this.pullingDownLock = false;
  }

  public void releasePullingUpLock()
  {
    this.pullingUpLock = false;
  }

  public void setAdapter(PullToRequestAdatper paramPullToRequestAdatper)
  {
    this.adapter = paramPullToRequestAdatper;
    removeAllViews();
    this.bodyView = ((View)paramPullToRequestAdatper.getBodyView());
    RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-1, -1);
    localLayoutParams1.addRule(9);
    localLayoutParams1.addRule(11);
    localLayoutParams1.addRule(10);
    addView(this.bodyView, localLayoutParams1);
    this.headerView = paramPullToRequestAdatper.getHeaderView();
    this.headerView.setLayoutParams(new RelativeLayout.LayoutParams(-2, -2));
    this.headerView.measure(0, 0);
    this.headerHeight = this.headerView.getMeasuredHeight();
    RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-2, this.headerHeight);
    localLayoutParams2.addRule(9);
    localLayoutParams2.addRule(11);
    localLayoutParams2.addRule(10);
    localLayoutParams2.topMargin = (-this.headerHeight);
    addView(this.headerView, localLayoutParams2);
    this.footerView = paramPullToRequestAdatper.getFooterView();
    this.footerView.setLayoutParams(new RelativeLayout.LayoutParams(-2, -2));
    this.footerView.measure(0, 0);
    this.footerHeight = this.footerView.getMeasuredHeight();
    RelativeLayout.LayoutParams localLayoutParams3 = new RelativeLayout.LayoutParams(-2, this.headerHeight);
    localLayoutParams3.addRule(9);
    localLayoutParams3.addRule(11);
    localLayoutParams3.addRule(12);
    localLayoutParams3.bottomMargin = (-this.headerHeight);
    addView(this.footerView, localLayoutParams3);
  }

  public void stopPulling()
  {
    long l = System.currentTimeMillis() - this.pullTime;
    if (l < 1000L)
    {
      postDelayed(this.stopAct, 1000L - l);
      return;
    }
    post(this.stopAct);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.gui.PullToRequestView
 * JD-Core Version:    0.6.2
 */